package org.sibutu.plugin.struts2.jcr.wrapper;

import org.sibutu.plugin.struts2.jcr.wrapper.TextPropsWrapper;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import java.util.Map;

/**
 * @author Max Skripnikov
 */
public class TextPropWrapperUtils {
  WrapperFactory wrapperFactory;
  private Map<String,NodeTextPropRetriever> titleRetrievers;
  private Map<String,Map<String,String>> textPropSubstitutions;

  public Node wrap(Node node) throws RepositoryException {
    return node instanceof TextPropsWrapper ? 
        node :
        new TextPropsWrapper(node, textPropSubstitutions.get(node.getName()), titleRetrievers.get(node.getName()), wrapperFactory);
  }

  public void setTitleRetrievers(Map<String, NodeTextPropRetriever> titleRetrievers) {
    this.titleRetrievers = titleRetrievers;
  }

  public void setTextPropSubstitutions(Map<String, Map<String, String>> textPropSubstitutions) {
    this.textPropSubstitutions = textPropSubstitutions;
  }

  public void setWrapperFactory(WrapperFactory wrapperFactory) {
    this.wrapperFactory = wrapperFactory;
  }
}
